from django import template
from django.http import HttpRequest
from mhlandscaping.apps.service.models import Service, Category
import settings

register = template.Library()

@register.inclusion_tag('service/templates/_sidebar_services.html', takes_context=True)
def sidebar_services(context):
	categories = []

	try:
		categories =  Category.objects.all().filter(active = True).order_by('name')
	except:
		pass

	return {
		'categories': categories,
		'settings': settings,
	}

@register.inclusion_tag('service/templates/_sidebar_related_services.html', takes_context=True)
def sidebar_related_services(context, service_id):
	service = Service.objects.get(id = service_id, active = True)

	try:
		services = Service.objects.filter(active = True, category__id = service.category.id)
		services = services.exclude(id = service_id).order_by('name')
	except:
		pass
	
	return {
		'services': services,
		'service_id': service_id,
		'settings': settings,
	}
	